#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from rest_framework.authentication import BaseAuthentication
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from django.contrib.auth import get_user_model


class CustomAuthentication(BaseAuthentication):
    """自定义认证方式"""

    def authenticate(self, request):
        """认证方法，request:本次客户端发送过来的http请求对象"""
        user = request.query_params.get("user")
        # pwd = request.query_params.get("pwd")
        # if user != "root" or pwd != "houmen":
        #     return None
        user = get_user_model().objects.filter(username=user).first()
        return (user, None)  # 固定格式返回，（用户模型,None）
